class Solution {
public:
    string countAndSay(int n) {
        string ret;
        string s = "1";
        if (n == 1)
            return "1";
        for (int j = 1; j < n; j++) {
            char num = s[0];
            int count = 1;
            for (int i = 1; i < s.size(); i++) {
                if (s[i] != num) {
                    ret += (count + '0');
                    ret += num;
                    num = s[i];
                    count = 1;

                }
                else {
                    count++;
                }
            }
            if (s[s.size() - 1] == num) {
                ret += (count + '0');
                ret += num;
            }
            s = ret;
            ret = "";
        }
        return s;
    }
};